﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ActionRegistrationWeb.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Cadastro de Actions</title>
    <link rel="Stylesheet" href="Action.css" />

    <script language="javascript">
        function ResetFormForInsert() {
            document.all.hdnActionId.value = "";
            document.all.txtAction.value = "";
            document.all.txtMethodName.value = "";
            document.all.txtMethodNameKernel.value = "";
            document.all.chkIsKernelPlus.value = false;
            ResetGridColor('datagridAction');
            actionForm.txtAction.focus();
        }
        function GridOnMouseOver(linha) {
            if (linha.bgColor != "#c0c0c0")
                linha.bgColor = "#f0f0f0";
        }

        function GridOnMouseOut(linha) {
            if (linha.bgColor != "#c0c0c0")
                linha.bgColor = "#ffffff";
        }

        function GridMouseDblClick(dataGrid, linha) {
            grid = eval(dataGrid);
            var rows = grid.getElementsByTagName("tr");

            for (i = 0; i < rows.length; i++) {
                rows[i].bgColor = "#ffffff";
                inputs = rows[i].getElementsByTagName("input");
                for (j = 0; j < inputs.length; j++) {
                    if (inputs[j].type == "checkbox")
                        inputs[j].checked = false;
                }
            }

            linha.bgColor = "#c0c0c0";
            linha.getElementsByTagName("input")[0].checked = true;

            tds = linha.getElementsByTagName("td");

            document.all.hdnSelected.value = "";
            document.all.hdnActionId.value = tds[1].firstChild.data;
            document.all.txtAction.value = tds[2].firstChild.data;
            document.all.txtMethodName.value = tds[3].firstChild.data;
            document.all.txtMethodNameKernel.value = tds[4].firstChild.data;
            document.all.chkIsKernelPlus.checked = tds[5].firstChild.data == "Sim" ? true : false;
            
            if (document.all.rfvtxtMethodNameKernel.attributes["enabled"] != null)
                document.all.rfvtxtMethodNameKernel.attributes["enabled"].value = tds[5].firstChild.data == "Sim" ? "true" : "false";

            document.all.btDeleteSelected.disabled = false;
        }

        function GridMouseClick(datagrid, idCheckBox) {
            document.all.hdnActionId.value = "";
            document.all.txtAction.value = "";
            document.all.txtMethodName.value = "";
            document.all.txtMethodNameKernel.value = "";
            document.all.chkIsKernelPlus.value = false;

            grid = eval(datagrid);
            var rows = grid.getElementsByTagName("tr");

            for (i = 1; i < rows.length; i++) {
                inputs = rows[i].getElementsByTagName("input");
                for (j = 0; j < inputs.length; j++) {
                    if (inputs[j].type == "checkbox" && inputs[j].id == idCheckBox) {
                        if (inputs[j].checked) {
                            rows[i].bgColor = "#ffffff";
                            inputs[j].checked = false;
                        }
                        else {
                            rows[i].bgColor = "#c0c0c0";
                            inputs[j].checked = true;
                        }
                        break;
                    }
                }
            }

            GetSelectedItems(grid);
        }

        function GetSelectedItems(grid) {
            document.all.hdnSelected.value = "";

            var rows = grid.getElementsByTagName("tr");

            for (i = 1; i < rows.length; i++) {
                inputs = rows[i].getElementsByTagName("input");
                for (j = 0; j < inputs.length; j++) {
                    if (inputs[j].type == "checkbox" && inputs[j].checked) {
                        document.all.hdnSelected.value += inputs[j].id + ",";
                    }
                }
            }

            document.all.hdnSelected.value = document.all.hdnSelected.value.substring(0, document.all.hdnSelected.value.length - 1);
            if (document.all.hdnSelected.value.length == 0)
                document.all.btDeleteSelected.disabled = true;
            else
                document.all.btDeleteSelected.disabled = false;
        }

        function ResetGridColor(datagrid) {
            grid = eval(datagrid);
            var rows = grid.getElementsByTagName("tr");

            for (i = 1; i < rows.length; i++) {
                inputs = rows[i].getElementsByTagName("input");
                for (j = 0; j < inputs.length; j++) {
                    if (inputs[j].type == "checkbox") {
                        inputs[j].checked = false;
                        rows[i].bgColor = "#ffffff";
                    }
                }
            }
        }

        function MudarValidacao() {
            if (document.all.rfvtxtMethodNameKernel.attributes["enabled"] != null)
                document.all.rfvtxtMethodNameKernel.attributes["enabled"].value = document.all.chkIsKernelPlus.checked;
        }
             
    </script>
</head>
<body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0">
    <form id="actionForm" runat="server">
    <asp:ScriptManager ID="ScriptManagerService" runat="server" OnAsyncPostBackError="ScriptManagerService_AsyncPostBackError" EnablePartialRendering="true" />

    <script type="text/javascript" language="javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

        function EndRequestHandler(sender, args) {
            if (args.get_error() != undefined && args.get_error().httpStatusCode == '500') {
                var errorMessage = args.get_error().message
                args.set_errorHandled(true);
                alert(errorMessage);
            }
        }
        
    </script>
        
    
    <asp:UpdatePanel ID="UpdatePanelService" runat="server">
        <ContentTemplate>   
            <input type="hidden" id="hdnActionId" name="hdnActionId" runat="server" />
            <input type="hidden" id="hdnSelected" name="hdnSelected" runat="server" />
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" DisplayMode="List" ShowMessageBox="True" ShowSummary="False" />
            <table width="100%">
                <tr>
                    <td style="text-align: center">
                        <table class="aviso">
                            <tr>
                                <td>O nome da Action deverá ser cadastrada no seguinte padrão: [Módulo].[Submódulo].[Classe].[Método]</td>
                            </tr>
                        </table>                        
                    </td>
                </tr>
                <tr height="1">
                    <td>
                        <fieldset>
                            <legend>Formulário de Cadastro</legend>
                            <table>
                                <tr valign="middle">
                                    <td>
                                        Action:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtAction" runat="server" Width="150" />
                                        <asp:RequiredFieldValidator ID="rfvtxtAction" runat="server" ControlToValidate="txtAction"
                                            ErrorMessage="Favor informar o nome do Action" SetFocusOnError="True" Display="None"></asp:RequiredFieldValidator>
                                    </td>
                                    <td width="10">
                                        &nbsp;
                                    </td>
                                    <td>
                                        Método:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtMethodName" runat="server" Width="150" />
                                        <asp:RequiredFieldValidator ID="rfvtxtMethodName" runat="server" ControlToValidate="txtMethodName"
                                            ErrorMessage="Favor informar o nome do Método" SetFocusOnError="True" Display="None"></asp:RequiredFieldValidator>
                                    </td>
                                    <td width="10">
                                        &nbsp;
                                    </td>
                                    <td>
                                        Método Alternativo:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtMethodNameKernel" runat="server" Width="150" />
                                        <asp:RequiredFieldValidator ID="rfvtxtMethodNameKernel" runat="server" ControlToValidate="txtMethodNameKernel"
                                            ErrorMessage="Favor informar o nome do Método Alternativo" SetFocusOnError="True" Display="None"
                                            Enabled="false"></asp:RequiredFieldValidator>
                                    </td>
                                    <td width="10">
                                        &nbsp;
                                    </td>
                                    <td>
                                        Kernel Mais:
                                    </td>
                                    <td>
                                    <%-- AutoPostBack="true"  OnCheckedChanged="chkIsKernelPlus_CheckedChanged" --%>
                                        <%--<asp:CheckBox ID="chkIsKernelPlus" runat="server" CausesValidation="false" onchange="MudarValidacao();" />--%>
                                        <input type="checkbox" id="chkIsKernelPlus" runat="server" onchange="MudarValidacao();" />
                                    </td>
                                    <td width="10">
                                        &nbsp;
                                    </td>
                                    <td>
                                        <asp:Button ID="btSave" runat="server" Text="Salvar" OnClick="btSave_Click" />
                                    </td>
                                </tr>
                            </table>
                        </fieldset>
                    </td>
                </tr>
                <tr height="1">
                    <td>
                        <table width="100%">
                            <tr valign="top">
                                <td width="1">
                                    <asp:Button ID="btDeleteSelected" runat="server" Text="Deletar itens selecionados"
                                        Enabled="false" OnClick="btDeleteSelected_Click" />
                                </td>
                                <td width="1">
                                    <input type="button" id="btNewItem" value="Inserir novo item" onclick="ResetFormForInsert()" />
                                </td>
                                <td width="99%" align="right">
                                    <asp:Label ID="lblMessage" runat="server" />
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td>
                        <table width="100%">
                            <tr valign="top">
                                <td id="grdForm" runat="server"></td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>
